<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<table id="goodsData"></table>

<div id="goodsMenu" class="easyui-menu" data-options="onClick:menuHandler" style="width:120px;display: none">
		<div data-options="name:'showMoreit',iconCls:'icon-reload'">预览</div>
		<div data-options="name:'showOK',iconCls:'icon-reload'">确认审核</div>
		<div id="groundingit"  data-options=" name:'groundingit',iconCls:'icon-add'">上架商品</div>
		<div  id="undercarriageit"   data-options="name:'undercarriageit',iconCls:'icon-remove'">下架商品</div>
		<div class="menu-sep"></div>
		 <div>  
		 	<span>编辑</span>  
	        <div >  
	            <div  data-options="name:'editBodyIt',iconCls:'icon-edit'">编辑主体</div>
				<div class="menu-sep"></div>
				<div  data-options="name:'editDescribeIt',iconCls:'icon-edit'">编辑商品描述</div>
				<div class="menu-sep"></div>
				<div   data-options="name:'queryfarmatit',iconCls:'icon-edit'">编辑规格</div>
				<div class="menu-sep"></div>
				<div  data-options=" name:'querypropertyit',iconCls:'icon-edit'">编辑属性</div>
        </div>  
        </div>  
		<div class="menu-sep"></div>
		<div >取消</div>
</div>
<script type="text/javascript">
/* 读取用户信息并设置到表格 */
var goodsData=$('#goodsData').datagrid({
	singleSelect:true,
	url:'goods/getGoodsList',
	striped:true,
	loadMsg:"正在加载中...",
	pagination:true,
	pageNumber:1,
	pageSize:10,
	pageList:[10,20,30,40,50],
	remoteSort:false,
	fit:true,
	fitColumns:true,
	//toolbar:"#goodsGrid_bar",
	columns:[[
	      	{field:'gId',sortable:true,align:'center',checkbox:true},
	      	{field:'cId',title:'直接类目ID',width:100,align:'center'},
	      	{field:'cName',title:'直接类目名',width:150,align:'center'},
	  		{field:'gTitle',title:'商品名',width:150,align:'center'},
	  		{field:'gSellPoint',title:'商品卖点',width:150,align:'center'},
	  		{field:'gMainImage',title:'商品主图',width:150,align:'center',
	  			formatter: function(value,row,index){
					return "<image style='width:60px;height:60px;' src='" +row.gMainImage+"'/>";
	  			}		
	  		},
	  		{field:'gPrice',title:'价格(元)',width:100,align:'center',
	  			formatter: function(value,row,index){
					return (row.gPrice/100);
	  			}	
	  		},
	  		{field:'gBarcode',title:'二维码',width:100,align:'center'},
	  		{field:'gnum',title:'商品库存',width:100,align:'center'},
	  		{field:'gStatus',title:'商品状态',width:100,align:'center',
	  			formatter: function(value,row,index){
	  				if(row.gStatus==1){
	  					return "<span style='color:red;'>待审核</span>";
	  				}else if(row.gStatus==2){
	  					return "<span style='color:yellow;'>待上架</span>";
	  				}else if(row.gStatus==3){
	  					return "<span style='color:green;'>已上架</span>";
	  				}else if(row.gStatus==4){
	  					return "<span style='color:black;'>已下架</span>";
	  				}
	  			}		
	  		},
	  		{field:'gAddTime',title:'添加时间',width:180,align:'center',
	  			formatter: function(value,row,index){
					return getDate(row.gAddTime.toString());
	  			}
	  		},
	  		{field:'gUpdateTime',title:'更新时间',width:180,align:'center',
	  			formatter: function(value,row,index){
	  				if(row.gUpdateTime!=""&&row.gUpdateTime!=undefined){
	  					return getDate(row.gUpdateTime.toString());
	  				}
	  			}	
	  		}]],
	  		onRowContextMenu: function(e, rowIndex, rowData){
	  			if(rowIndex!=-1){
			  			e.preventDefault();
			  			$('#goodsData').datagrid('selectRow',rowIndex);
			  			$('#goodsMenu').menu('show',{
							left: e.pageX,
							top: e.pageY
						});
			  			var itemEl = $('#groundingit')[0];  // 菜单项元素
			  			var itemEl1 = $('#undercarriageit')[0];  // 菜单项元素
			  			 $('#goodsMenu').menu('enableItem', itemEl);
			  			 $('#goodsMenu').menu('enableItem', itemEl1);
			  			if($('#goodsData').datagrid('getSelected').gStatus!=2){
			  				 $('#goodsMenu').menu('disableItem', itemEl);
			  			}
						 if($('#goodsData').datagrid('getSelected').gStatus!=3){
			  				 $('#goodsMenu').menu('disableItem', itemEl1);
			  			}
	  			}
	  		}

	
}); 
function menuHandler(item){
	if(item.name=="showMoreit"){//预览审核
		var gId=$('#goodsData').datagrid('getSelected').gId;
		window.open("back/showmore?id="+gId,"_blank");

	}else if(item.name=="showOK"){//确认审核
		$.get("goods/examOK",{id:$('#goodsData').datagrid('getSelected').gId},function(data){
			if(data.status==200){
				$('#goodsData').datagrid('reload');
			}
		});

	}else if(item.name=="groundingit"){//上架商品
			$.get("goods/groundingitGoodsById",{id:$('#goodsData').datagrid('getSelected').gId},function(data){
				if(data.status==200){
					$('#goodsData').datagrid('reload');
					$.messager.show({
						title:'成功提示',
						msg:'商品上架成功',
						timeout:5000,
						showType:'slide'
					});
				}else{
					$.messager.alert('错误',data.data,'info');
				}
			});
	}else if(item.name=="undercarriageit"){//下架
		$.get("goods/undercarriageitGoodsById",{id:$('#goodsData').datagrid('getSelected').gId},function(data){
			if(data.status==200){
				$('#goodsData').datagrid('reload');
				$.messager.show({
					title:'成功提示',
					msg:'商品下架成功',
					timeout:5000,
					showType:'slide'
				});
			}else{
				$.messager.alert('错误',data.data,'info');
			}
		});
	}else if(item.name=="editBodyIt"){//编辑主体
		var gId=$('#goodsData').datagrid('getSelected').gId;
		commenUtil.createWindow({
 			id:gId,
 			loadMsg:"正在加载中...",
 			title:'编辑主体',
     		url : "back/goodsInfoEdit",
     	})
	}else if(item.name=="queryfarmatit"){//编辑规格
		var gId=$('#goodsData').datagrid('getSelected').gId;
			commenUtil.createWindow({
	 			id:gId,
	 			loadMsg:"正在加载中...",
	 			title:'编辑规格',
	     		url : "back/goods-format-param-edit",
	     	})
	}else if(item.name=="querypropertyit"){//编辑属性
		var gId=$('#goodsData').datagrid('getSelected').gId;
		commenUtil.createWindow({
 			id:gId,
 			loadMsg:"正在加载中...",
 			title:'编辑属性',
     		url : "back/goods-property-param-edit",
     	})
		
		/* 
			if(data.status==200){
				
			}else{
				$.messager.alert('错误',data.data,'info');
			}
		}); */
	}else if(item.name=="editDescribeIt"){//编辑商品描述
		var gId=$('#goodsData').datagrid('getSelected').gId;
		
			commenUtil.createWindow({
	 			id:gId,
	 			loadMsg:"正在加载中...",
	 			title:'编辑商品描述',
	     		url : "back/goodsDescribeEdit",
	     	});
		
	}
}

</script>